package com.anlogic.sdk.ui.tests.utils;

import java.util.regex.Pattern;

import org.eclipse.swt.SWT;

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;

import com.anlogic.sdk.ui.tests.utils.SF1Utils.ConsoleTextMatches;

public class ProjectAttributeUtils {

	public static void riscvTestcomboBox(SWTWorkbenchBot bot, String process, int index, String Selection, String args)
			throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();
		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("riscv");
		bot.tree().getTreeItem("Executable").getNode("RISCV C Project (SF1)").select();
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("sf1");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("riscv").select();
		
		bot.tree().getTreeItem("riscv").doubleClick();

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("riscv");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		
		SWTBotShell shell = bot.shell("Properties for riscv");
		shell.activate();

		SWTBotTree tree = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(process).select();

		// bot.sleep(1000); // 等右侧 UI 加载

		bot.comboBox(index).setSelection(Selection);

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [riscv])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}

	}

	public static void riscvTestCheckBox(SWTWorkbenchBot bot, String process, String checkString, String args)
			throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();
		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("riscv");
		bot.tree().getTreeItem("Executable").getNode("RISCV C Project (SF1)").select();
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("sf1");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("riscv").select();
		
		bot.tree().getTreeItem("riscv").doubleClick();

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("riscv");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框
		SWTBotShell shell = bot.shell("Properties for riscv");
		shell.activate();

		SWTBotTree tree = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		
	//	SWTBotTree tree = bot.tree(0);

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 60 * 1000);  
		
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		 
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();
		
		bot.tree(1).getTreeItem(process).select();

		bot.sleep(1000); // 等右侧 UI 加载


		SWTBotCheckBox checkBox = bot.checkBox(checkString);
		if (!checkBox.isChecked()) {
			checkBox.click(); // 如果没勾选则点击勾选
		}

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [riscv])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}

	}

	public static void riscvTesttextWithLabel(SWTWorkbenchBot bot, String process, String lable, String text1,
			String args) throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();
		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("riscv");
		bot.tree().getTreeItem("Executable").getNode("RISCV C Project (SF1)").select();
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("sf1");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("riscv").select();
		
		bot.tree().getTreeItem("riscv").doubleClick();

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("riscv");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.tree().isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		
		SWTBotShell shell = bot.shell("Properties for riscv");
		shell.activate();

		SWTBotTree tree1 = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree1.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree1.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree1.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		

		bot.tree(0).getTreeItem("C/C++ Build").select();
		bot.tree(0).getTreeItem("C/C++ Build").expand();
		bot.tree(0).getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(process).select();

		bot.sleep(1000); // 等右侧 UI 加载

		bot.textWithLabel(lable).setText(text1);

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [riscv])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}

	}

	public static void riscvTestcomboBoxWithNode(SWTWorkbenchBot bot, String tree, String process, int index,
			String Selection, String args) throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();
		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("riscv");
		bot.tree().getTreeItem("Executable").getNode("RISCV C Project (SF1)").select();
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("sf1");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("riscv").select();
		
		bot.tree().getTreeItem("riscv").doubleClick();

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("riscv");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.tree().isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		bot.tree(0).setFocus();
		bot.waitUntil(Conditions.shellIsActive("Properties for riscv"), 30*1000);
		SWTBotShell shell = bot.shell("Properties for riscv");
		shell.activate();

		SWTBotTree tree1 = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree1.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree1.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree1.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		

		bot.tree(0).getTreeItem("C/C++ Build").select();
		bot.tree(0).getTreeItem("C/C++ Build").expand();
		bot.tree(0).getTreeItem("C/C++ Build").getNode("Settings").select();

		// bot.tree(1).getTreeItem(process).select();
		bot.tree(1).getTreeItem(tree).getNode(process).select();
		bot.sleep(1000); // 等右侧 UI 加载

		bot.comboBox(index).setSelection(Selection);
		// bot.checkBox("Compressed extension (RVC)").click();

		// bot.textWithLabel("Small data limit").setText("33");
		bot.waitUntil(Conditions.shellIsActive("Properties for riscv"), 30 * 1000); // 或对应你的属性窗口标题
		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [riscv])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}

	}

	public static void riscvTestCheckBoxWithNode(SWTWorkbenchBot bot, String tree, String process, String checkString,
			String args) throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();
		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("riscv");
		bot.tree().getTreeItem("Executable").getNode("RISCV C Project (SF1)").select();
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("sf1");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("riscv").select();
		
		bot.tree().getTreeItem("riscv").doubleClick();

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("riscv");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.tree().isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
	

		SWTBotShell shell = bot.shell("Properties for riscv");
		shell.activate();

		SWTBotTree tree1 = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree1.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree1.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree1.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		

		bot.tree(0).getTreeItem("C/C++ Build").select();
		bot.tree(0).getTreeItem("C/C++ Build").expand();
		bot.tree(0).getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(tree).getNode(process).select();

		bot.sleep(1000); // 等右侧 UI 加载

		SWTBotCheckBox checkBox = bot.checkBox(checkString);
		if (!checkBox.isChecked()) {
			checkBox.click(); // 如果没勾选则点击勾选
		}

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [riscv])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);
			// Thread.sleep(000);
			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}

	}

	public static void riscvTesttextWithLabelWithNode(SWTWorkbenchBot bot, String tree, String process, String lable,
			String text1, String args) throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();
		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("riscv");
		bot.tree().getTreeItem("Executable").getNode("RISCV C Project (SF1)").select();
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("sf1");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("riscv").select();
		
		bot.tree().getTreeItem("riscv").doubleClick();
		

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("riscv");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.tree().isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		bot.tree(0).setFocus();
		
		SWTBotShell shell = bot.shell("Properties for riscv");
		shell.activate();

		SWTBotTree tree1 = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree1.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree1.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree1.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		

		
		bot.tree(0).getTreeItem("C/C++ Build").select();
		bot.tree(0).getTreeItem("C/C++ Build").expand();
		bot.tree(0).getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(tree).getNode(process).select();

		bot.sleep(1000); // 等右侧 UI 加载

		bot.textWithLabel(lable).setText(text1);

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("riscv").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [riscv])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);
			// Thread.sleep(000);
			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}

	}
	public static void armTestcomboBox(SWTWorkbenchBot bot, String process, int index, String Selection, String args)
			throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();

		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("arm");
		bot.tree().getTreeItem("Executable").getNode("Empty Project").select();
		bot.table().select("Arm Cross GCC");
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("dr1m90");
		bot.comboBox(2).setSelection("AArch32");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").doubleClick();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("New").menu("File").click();
		bot.textWithLabel("File na&me:").setText("main.c");
		bot.button("Finish").click();
		bot.editorByTitle("main.c").show();

		SWTBotEditor editor = bot.activeEditor();

		editor.toTextEditor()
				.setText("#include<stdio.h>\n" + "int main(){\n" + "    printf(\"aa\");\n" + "    \n" + "}\n");

		// 模拟 Ctrl + S 保存
		editor.save();
		// bot.styledText().pressShortcut(SWT.CTRL, 's');

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("arm");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		
		SWTBotShell shell = bot.shell("Properties for arm");
		shell.activate();

		SWTBotTree tree = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(process).select();

		// bot.sleep(1000); // 等右侧 UI 加载

		bot.comboBox(index).setSelection(Selection);

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [arm])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}

	}

	public static void armTestCheckBox(SWTWorkbenchBot bot, String process, String checkString, String args)
			throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();
		
		bot.waitUntil(Conditions.shellIsActive("New Project"), 10000);
		SWTBotShell shell = bot.shell("New Project");
		shell.activate();

		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("arm");
		bot.tree().getTreeItem("Executable").getNode("Empty Project").select();
		bot.table().select("Arm Cross GCC");
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("dr1m90");
		bot.comboBox(2).setSelection("AArch32");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").doubleClick();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("New").menu("File").click();
		bot.textWithLabel("File na&me:").setText("main.c");
		bot.button("Finish").click();
		bot.editorByTitle("main.c").show();

		SWTBotEditor editor = bot.activeEditor();

		editor.toTextEditor()
				.setText("#include<stdio.h>\n" + "int main(){\n" + "    printf(\"aa\");\n" + "    \n" + "}\n");

		// 模拟 Ctrl + S 保存
		editor.save();
		// bot.styledText().pressShortcut(SWT.CTRL, 's');

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("arm");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		
		SWTBotShell shell1 = bot.shell("Properties for arm");
		shell1.activate();

		SWTBotTree tree = shell1.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(process).select();

		// bot.sleep(1000); // 等右侧 UI 加载

		SWTBotCheckBox checkBox = bot.checkBox(checkString);
		if (!checkBox.isChecked()) {
			checkBox.click(); // 如果没勾选则点击勾选
		}

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [arm])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}
		


	}
	
	public static void armTesttextWithLabel(SWTWorkbenchBot bot, String process, String lable, String text1,
			String args)
			throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();

		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("arm");
		bot.tree().getTreeItem("Executable").getNode("Empty Project").select();
		bot.table().select("Arm Cross GCC");
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("dr1m90");
		bot.comboBox(2).setSelection("AArch32");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").doubleClick();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("New").menu("File").click();
		bot.textWithLabel("File na&me:").setText("main.c");
		bot.button("Finish").click();
		bot.editorByTitle("main.c").show();

		SWTBotEditor editor = bot.activeEditor();

		editor.toTextEditor()
				.setText("#include<stdio.h>\n" + "int main(){\n" + "    printf(\"aa\");\n" + "    \n" + "}\n");

		// 模拟 Ctrl + S 保存
		editor.save();
		// bot.styledText().pressShortcut(SWT.CTRL, 's');

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("arm");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		
		SWTBotShell shell = bot.shell("Properties for arm");
		shell.activate();

		SWTBotTree tree = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(process).select();

		// bot.sleep(1000); // 等右侧 UI 加载

	

		bot.sleep(1000); // 等右侧 UI 加载

		bot.textWithLabel(lable).setText(text1);

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [arm])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}
		


	}

	public static void armTestcomboBoxWithNode(SWTWorkbenchBot bot, String tree1, String process, int index,
			String Selection, String args) throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();

		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("arm");
		bot.tree().getTreeItem("Executable").getNode("Empty Project").select();
		bot.table().select("Arm Cross GCC");
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("dr1m90");
		bot.comboBox(2).setSelection("AArch32");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").doubleClick();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("New").menu("File").click();
		bot.textWithLabel("File na&me:").setText("main.c");
		bot.button("Finish").click();
		bot.editorByTitle("main.c").show();

		SWTBotEditor editor = bot.activeEditor();

		editor.toTextEditor()
				.setText("#include<stdio.h>\n" + "int main(){\n" + "    printf(\"aa\");\n" + "    \n" + "}\n");

		// 模拟 Ctrl + S 保存
		editor.save();
		// bot.styledText().pressShortcut(SWT.CTRL, 's');

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("arm");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		
		SWTBotShell shell = bot.shell("Properties for arm");
		shell.activate();

		SWTBotTree tree = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(tree1).getNode(process).select();

		// bot.sleep(1000); // 等右侧 UI 加载

		bot.comboBox(index).setSelection(Selection);

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [arm])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}



	}

	public static void armTestCheckBoxWithNode(SWTWorkbenchBot bot, String tree1, String process, String checkString,
			String args) throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();

		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("arm");
		bot.tree().getTreeItem("Executable").getNode("Empty Project").select();
		bot.table().select("Arm Cross GCC");
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("dr1m90");
		bot.comboBox(2).setSelection("AArch32");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").doubleClick();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("New").menu("File").click();
		bot.textWithLabel("File na&me:").setText("main.c");
		bot.button("Finish").click();
		bot.editorByTitle("main.c").show();

		SWTBotEditor editor = bot.activeEditor();

		editor.toTextEditor()
				.setText("#include<stdio.h>\n" + "int main(){\n" + "    printf(\"aa\");\n" + "    \n" + "}\n");

		// 模拟 Ctrl + S 保存
		editor.save();
		// bot.styledText().pressShortcut(SWT.CTRL, 's');

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("arm");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		
		SWTBotShell shell = bot.shell("Properties for arm");
		shell.activate();

		SWTBotTree tree = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(tree1).getNode(process).select();

		// bot.sleep(1000); // 等右侧 UI 加载

		bot.sleep(1000); // 等右侧 UI 加载

		SWTBotCheckBox checkBox = bot.checkBox(checkString);
		if (!checkBox.isChecked()) {
			checkBox.click(); // 如果没勾选则点击勾选
		}

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [arm])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}


	


	}

	public static void armTesttextWithLabelWithNode(SWTWorkbenchBot bot, String tree1, String process, String lable,
			String text1, String args) throws InterruptedException {
		bot.waitUntil(Conditions.shellIsActive("data - FutureDynasty"), 60 * 1000);

		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return bot.menu("File").menu("New").menu("Project...").isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "Menu 'Platform Project' is not available or not enabled.";
			}
		}, 60 * 1000);
		bot.menu("File").menu("New").menu("Project...").click();

		bot.tree().getTreeItem("C/C++").doubleClick();

		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").select();
		bot.tree().getTreeItem("C/C++").getNode("C/C++ Project").doubleClick();
		bot.table().select(0);
		bot.table().getTableItem(0).doubleClick();
		bot.textWithLabel("&Project name:").setText("arm");
		bot.tree().getTreeItem("Executable").getNode("Empty Project").select();
		bot.table().select("Arm Cross GCC");
		bot.button("Next >").click();
		bot.button("Finish").click();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Reset Project").click();
		bot.comboBox().setSelection("dr1m90");
		bot.comboBox(2).setSelection("AArch32");
		bot.button("Reset").click();
		bot.button("Close").click();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").select();
		bot.tree().getTreeItem("arm").doubleClick();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("New").menu("File").click();
		bot.textWithLabel("File na&me:").setText("main.c");
		bot.button("Finish").click();
		bot.editorByTitle("main.c").show();

		SWTBotEditor editor = bot.activeEditor();

		editor.toTextEditor()
				.setText("#include<stdio.h>\n" + "int main(){\n" + "    printf(\"aa\");\n" + "    \n" + "}\n");

		// 模拟 Ctrl + S 保存
		editor.save();
		// bot.styledText().pressShortcut(SWT.CTRL, 's');

		bot.viewByTitle("Project Explorer").show();
		SWTBotTreeItem item = bot.viewByTitle("Project Explorer").bot().tree().getTreeItem("arm");

		// 展开、确保 item 可见（可选）
		item.select();

		bot.activeShell().pressShortcut(SWT.ALT, SWT.CR); // Alt + Enter 打开属性对话框

		
		SWTBotShell shell = bot.shell("Properties for arm");
		shell.activate();

		SWTBotTree tree = shell.bot().tree(0); // 或者 tree(1)，根据实际尝试

		// 先列出所有项，方便排查
		for (SWTBotTreeItem item1 : tree.getAllItems()) {
		    System.out.println("Tree item1: [" + item1.getText() + "]");
		}
		bot.waitUntil(new DefaultCondition() {
			@Override
			public boolean test() throws Exception {
				// 检查菜单是否可用
				return tree.isEnabled();
			}

			@Override
			public String getFailureMessage() {
				return "not available or not enabled.";
			}
		}, 60 * 1000);
		

		bot.waitUntil(new DefaultCondition() {
		    @Override
		    public boolean test() {
		        try {
		            return tree.getTreeItem("C/C++ Build") != null;
		        } catch (WidgetNotFoundException e) {
		            return false;
		        }
		    }

		    @Override
		    public String getFailureMessage() {
		        return "Tree item 'C/C++ Build' 一直未出现";
		    }
		}, 30 * 1000);  
		tree.getTreeItem("C/C++ Build").select();
		tree.getTreeItem("C/C++ Build").expand();
		tree.getTreeItem("C/C++ Build").getNode("Settings").select();

		bot.tree(1).getTreeItem(tree1).getNode(process).select();

		// bot.sleep(1000); // 等右侧 UI 加载

		bot.textWithLabel(lable).setText(text1);

		bot.button("Apply").click();
		bot.button("Apply and Close").click();
		bot.viewByTitle("Project Explorer").show();
		bot.viewByTitle("Project Explorer").bot().tree().select("arm").contextMenu("Build Project").click();
		bot.viewByTitle("Console (CDT Build Console [arm])").show();
		SWTBotView consoleView = bot.viewByPartName("Console");
		consoleView.setFocus();
		if (consoleView.isActive()) {
			System.out.println(111);
			Pattern p = Pattern.compile(".*" + args + ".*", Pattern.DOTALL);

			bot.waitUntil(consoleTextMatches(consoleView, p), 60 * 1000);
		}
	}
	

	protected static ICondition consoleTextMatches(SWTBotView consoleView, Pattern pattern) {
		return new ConsoleTextMatches(consoleView, pattern);
	}

	static class ConsoleTextMatches implements ICondition {
		private final SWTBotView view;
		private Pattern pattern;

		public ConsoleTextMatches(SWTBotView view, Pattern pattern) {
			this.view = view;
			this.pattern = pattern;
		}

		@Override
		public boolean test() {
			if (view.isActive()) {
				String output = view.bot().styledText().getText();
				java.util.regex.Matcher m = pattern.matcher(output);
				return m.matches();
			}
			return false;
		}

		@Override
		public void init(SWTBot bot) {
		}

		@Override
		public String getFailureMessage() {
			return "no matcher agrs";
		}
	}
	
			
	

}
